package com.example.yls.demoa;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.Toast;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    private RecyclerView rlvStu;
    private ArrayList<Student> studentArrayList = new ArrayList<>();
    private StuAdapter adapter;
    private Button btnAdd;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main );
        initStudentArrayList();

        adapter = new StuAdapter( MainActivity.this,
                studentArrayList );

        rlvStu = findViewById( R.id.rlv_stu );
        rlvStu.setAdapter( adapter );
        LinearLayoutManager manager = new LinearLayoutManager( MainActivity.this );
        rlvStu.setLayoutManager( manager );


        btnAdd=findViewById( R.id.stu_add );
                btnAdd.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick( View view ) {
                Intent intent = new Intent(  );
                intent.setClass( MainActivity.this,StudentAddActivity.class );
                startActivity( intent );
            }
        } );
    }


    private void initStudentArrayList() {
        Student s1 = new Student("18001","张毅",20, R.drawable.dog1);
        Student s2 = new Student("18002","张二",21, R.drawable.dog2);
        Student s3 = new Student("18003","张三",22, R.drawable.dog3);
        Student s4 = new Student("18004","张四",23, R.drawable.dog4);
        Student s5 = new Student("18005","张五",24, R.drawable.dog5);
        studentArrayList.add(s1);
        studentArrayList.add(s2);
        studentArrayList.add(s3);
        studentArrayList.add(s4);
        studentArrayList.add(s5);
    }
}
